package fr.ensai.lignededix.bd;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;

import fr.ensai.lignededix.exceptions.FonctionalException;
import fr.ensai.lignededix.exceptions.TechnicalException;
import fr.ensai.lignededix.metier.jeton.Jeton;
import fr.ensai.lignededix.metier.partie.Partie;

public class JetonDAO extends DAO<Jeton> {

	
	@Override
	public int create(Jeton obj) throws FonctionalException {

		int idJeton=-1;
		try {

			Statement instruction = connect.createStatement();

			ResultSet resultat = instruction.executeQuery("SELECT seqJeton.nextval from dual");
			resultat.next();
			idJeton=resultat.getInt(1);

			if (obj.isSimple()) {
				instruction.executeUpdate("INSERT INTO Jeton (idJeton,typeJeton,valeur) VALUES ("+idJeton+","+"0"+","+obj.getValeur()+")");
			} 

			if (obj.isMulti()) {
				instruction.executeUpdate("INSERT INTO Jeton (idJeton,typeJeton,valeur) VALUES ("+idJeton+","+"1"+","+obj.getValeur()+")");
			} 

			if (obj.isJoker()) {
				instruction.executeUpdate("INSERT INTO Jeton (idJeton,typeJeton,valeur) VALUES ("+idJeton+","+"2"+","+obj.getValeur()+")");
			} 
			if (obj.isDiable())	{
				instruction.executeUpdate("INSERT INTO Jeton (idJeton,typeJeton,valeur) VALUES ("+idJeton+","+"3"+","+obj.getValeur()+")");
			}
		}catch (SQLException e) {
			throw new FonctionalException("La sauvegarde du coup a echoue");
		}

		return idJeton;
	}

	@Override
	public Jeton find(int id) throws FonctionalException {
		throw new UnsupportedOperationException();
	}
	
	
	@Override
	public Jeton update(Jeton obj) {

		throw new UnsupportedOperationException();
	}

	@Override
	public void delete(Jeton obj) {
		throw new UnsupportedOperationException();

	}

	@Override
	public boolean isPseudoValide(String pseudo) throws FonctionalException, TechnicalException {
		throw new UnsupportedOperationException();
	}

	@Override
	public int authentifier(String pseudo, String mdp)
			throws FonctionalException, TechnicalException {
		throw new UnsupportedOperationException();
	}

	@Override
	public String calculerDesStatistiques(Jeton obj) throws FonctionalException {
		throw new UnsupportedOperationException();
	}

	@Override
	public List<Jeton> getAll(int idUtilisateur1, int idUtilisateur2)
			throws FonctionalException {
		throw new UnsupportedOperationException();
	}

	@Override
	public void updateDateFin(Jeton obj) throws FonctionalException {
		throw new UnsupportedOperationException();

	}



	@Override
	public void executerRequete(String ligne) throws TechnicalException {
		throw new UnsupportedOperationException();

	}
	@Override
	public void sinscrireSurListeAttente(Jeton obj) throws FonctionalException {
		throw new UnsupportedOperationException();
		
	}

	@Override
	public List<Jeton> obtenirListeAttente(Jeton obj)
			throws FonctionalException {
		throw new UnsupportedOperationException();
	}

	@Override
	public void desinscrireListeAttente(Jeton obj) throws FonctionalException {
		throw new UnsupportedOperationException();
		
	}
	
	@Override
	public void updateScore(Partie partieInterrompueOuFinie)
			throws FonctionalException {
		throw new UnsupportedOperationException();
		
	}

	
	//Constructeur
	
	public JetonDAO(Connection connect) {
		this.connect=connect;
	}

	
	



}
